import pygame

pygame.init()

screen_w, screen_h = 640,480
screen = pygame.display.set_mode((640, 480))

timer = pygame.time.Clock()

keep_going = True
direction = [1,1]
radius = 20
x,y = radius,radius

while keep_going:
  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      keep_going = False
  screen.fill((0,0,0))
  pygame.draw.circle(screen, (255,0,0), (x,y), radius)
  x += direction[0]
  y += direction[1]
  if x >= (screen_w-radius) or x <= radius:
    direction[0] = -direction[0]
  if y >= (screen_h-radius) or y <= radius:
    direction[1] = -direction[1]
  pygame.display.update()

  timer.tick(60)
